<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title></title>
  <!--引入Vue-->
  <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<div class="root">
  <div :style="{opacity}">几个字</div>
  <button @click="bye">点我销毁</button>
</div>
</body>

<script type="text/javascript">
  const vm = new Vue({
    el: '.root',
    data: {
      name: 'Jack',
      opacity: 1
    },
    /**
     * 此时无法通过vm访问到data中的数据和methods里面的方法
     */
    beforeCreate() {
    },
    /**
     * 可以通过vm访问到data中的数据和methods里面的方法
     */
    created() {
    },
    beforeMount() {
    },
    mounted() {
      this.change()
    },
    beforeUpdate() {
    },
    updated() {
    },
    beforeDestroy() {
      console.log('beforeDestroy')
    },
    destroyed() {
      console.log('destroyed')
    },
    methods:{
      change(){
        setInterval(()=>{
          vm.opacity -= 0.01
          if(vm.opacity<=0){
            vm.opacity = 1
          }
        },16)
      },
      bye(){
        this.$destroy()
      }
    }
  })


</script>
</html>
